package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-11-20 23:43
 */
public class MaxProfit {
    public int maxProfit(int[] prices) {

        int min = Integer.MAX_VALUE, sell = 0;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < min) {
                min = prices[i];
            } else if ((prices[i] - min) > sell) {
                sell = prices[i] - min;
            }
        }
        return sell;

    }
}
